from django.apps import AppConfig
from django.db.models.signals import post_migrate


def initialize_web_info(sender, **kwargs):
    from .models import WebInfo

    # 检查是否已经存在 WebInfo 数据
    if not WebInfo.objects.exists():
        WebInfo.objects.create(
            slogan="欢迎来到我的网站！",
            announcement="这是网站的公告内容。",
            description="这是一个用 Django 开发的网站。",
            qq_contact="123456789",
            email_contact="admin@example.com",
            github_url="https://github.com/example",
            gitee_url="https://gitee.com/example",
            bilibili_url="https://www.bilibili.com/example"
        )
        print("WebInfo 数据已初始化")
    else:
        print("WebInfo 数据已存在，无需初始化")


class WebinfoConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'webinfo'

    def ready(self):
        # 连接信号
        post_migrate.connect(initialize_web_info, sender=self)
